var infoData = require('./infoData')();
var startData = require('../module/startData')();
// var CallbackEvent = require('CallbackEvent');
var self;
cc.Class({
    extends: cc.Component,

    properties: {
        back_bg: cc.Node,
        title1: cc.Label,
        title2: cc.Label,
        title3: cc.Label,
        progress_Bar: cc.Node,
        attack_num: cc.Label,
        count_list: cc.ScrollView,
        countItem: cc.Prefab,
        head_list: cc.ScrollView,
        headItem: cc.Prefab,
        head_png: cc.Sprite,
        All_info: cc.SpriteAtlas,
        EditBox: cc.EditBox,

    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        self = this;
        this.count_content = this.count_list.content;
        this.head_content = this.head_list.content;
        this.init();
        this.node.on('foobar', this.backfun);
        var fun=function(){};
        cc.find("loadbg").getComponent("loadbg").show(fun);

    },
    backfun(event) {
        self.head_png.getComponent(cc.Sprite).spriteFrame = self.All_info.getSpriteFrame(infoData.head_data[event.detail.id]);
        self.select_head = infoData.head_data[event.detail.id];
        event.stopPropagation();
    },

    init() {
        this.title1.string = infoData.title1;
        this.title2.string = infoData.title2;
        this.title3.string = infoData.title3;


        this.EditBox.string = startData.people_data.name;
        this.select_head= startData.people_data.head;
        this._name=startData.people_data.name;

        this.attack_num.string = infoData.attack_num;
        this.initlist();
    },
    initlist() {
        var count_data = infoData.count_data;
        for (let a = 0; a < count_data.length; a++) {
            let item = cc.instantiate(this.countItem);
            item.getComponent('info_count_Item').init(count_data[a]);
            this.count_content.addChild(item);
        }
        var head_data = infoData.head_data;
        for (let a = 0; a < head_data.length; a++) {
            let item = cc.instantiate(this.headItem);
            item.getComponent('info_head_item').init(head_data[a], a);
            this.head_content.addChild(item);
        }
    },
    back() {
        startData.people_data.head = this.select_head;
        startData.people_data.name = this._name;
        cc.director.loadScene("game_start");
    },
    start() {

    },
    onEditDidBegan: function (editbox, customEventData) {

    },

    onEditDidEnded: function (editbox, customEventData) {

    },
    onTextChanged: function (text, editbox, customEventData) {
        this._name = editbox.string;
        this.EditBox.string = this._name ;
    },

    onEditingReturn: function (editbox, customEventData) {
        this._name = editbox.string;
        this.EditBox.string = this._name ;
    },
    onDestroy() {
        this.node.off('foobar', this.backfun);
    },

    // update (dt) {},
});
